package cn.damai.mine.beancopy.normal;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import net.sf.cglib.beans.BeanCopier;

public class BeanCopierUtils {

	public static Map<String,BeanCopier> beanCopierMap = new HashMap<String,BeanCopier>();
    
    public static void copyProperties(Object source, Object target){
    	
    	long st2 = System.nanoTime(),et2;
    	
        String beanKey =  generateKey(source.getClass(), target.getClass());
        BeanCopier copier =  null;
        if(!beanCopierMap.containsKey(beanKey)){
             copier = BeanCopier.create(source.getClass(), target.getClass(), false);//��Ҫ���������ĵ�  �ɿ�����tomcat����ʱ ������Ӧ���copier ����map
             beanCopierMap.put(beanKey, copier);
        }else{
             copier = beanCopierMap.get(beanKey);
        }
        
        et2 =System.nanoTime();
        System.out.println("BeanCopierUtils.create耗时:"+TimeUnit.NANOSECONDS.toMillis((et2-st2))+"MS");
        
        copier.copy(source, target, null);
    }   
    private static String generateKey(Class<?> class1,Class<?>class2){
        return class1.toString() + class2.toString();
    }
	
}
